package com.liuliu.controller.zua;

import com.liuliu.common.annotation.Log;
import com.liuliu.common.core.controller.BaseController;
import com.liuliu.common.core.domain.AjaxResult;
import com.liuliu.common.core.domain.model.LoginUser;
import com.liuliu.common.core.page.TableDataInfo;
import com.liuliu.common.enums.BusinessType;
import com.liuliu.common.utils.ServletUtils;
import com.liuliu.common.utils.poi.ExcelUtil;
import com.liuliu.framework.web.service.TokenService;
import com.liuliu.zua.domain.ZuaGradeStudent;
import com.liuliu.zua.service.IZuaGradeStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 成绩Controller
 * 
 * @author ruoyi
 * @date 2021-03-22
 */
@RestController
@RequestMapping("/zua/grade")
public class ZuaGradeStudentController extends BaseController
{
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IZuaGradeStudentService zuaGradeStudentService;

    /**
     * 查询成绩列表
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZuaGradeStudent zuaGradeStudent)
    {
        // 把当前的的用户信息存入到这个查询条件中
        LoginUser loginUser = this.tokenService.getLoginUser(ServletUtils.getRequest());
        zuaGradeStudent.setRemark(loginUser.getUser().getNickName());
        startPage();
        List<ZuaGradeStudent> list = zuaGradeStudentService.selectZuaGradeStudentList(zuaGradeStudent);
        return getDataTable(list);
    }

    /**
     * 学生查询老师的时候不需要当前用户信息
     * @param zuaGradeStudent
     * @return
     */
    @GetMapping("/listStudent")
    public TableDataInfo listStudent(ZuaGradeStudent zuaGradeStudent)
    {
        startPage();
        List<ZuaGradeStudent> list = zuaGradeStudentService.selectZuaGradeStudentList(zuaGradeStudent);
        return getDataTable(list);
    }
    /**
     * 根据登录信息查询成绩信息
     * @param zuaGradeStudent
     * @return
     */
    @GetMapping("/listGradeByLoginId")
    public TableDataInfo listGradeByLoginId(ZuaGradeStudent zuaGradeStudent)
    {
        // 把当前的的用户信息存入到这个查询条件中
        LoginUser loginUser = this.tokenService.getLoginUser(ServletUtils.getRequest());
        zuaGradeStudent.setRemark(String.valueOf(loginUser.getUser().getUserId()));
        startPage();
        List<ZuaGradeStudent> list = zuaGradeStudentService.selectZuaGradeStudentListByLoginId(zuaGradeStudent);
        return getDataTable(list);
    }
    /**
     * 导出成绩列表
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:export')")
    @Log(title = "成绩", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZuaGradeStudent zuaGradeStudent)
    {
        List<ZuaGradeStudent> list = zuaGradeStudentService.selectZuaGradeStudentList(zuaGradeStudent);
        ExcelUtil<ZuaGradeStudent> util = new ExcelUtil<ZuaGradeStudent>(ZuaGradeStudent.class);
        return util.exportExcel(list, "grade");
    }

    /**
     * 获取成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return AjaxResult.success(zuaGradeStudentService.selectZuaGradeStudentById(gradeId));
    }

    /**
     * 新增成绩
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:add')")
    @Log(title = "成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZuaGradeStudent zuaGradeStudent)
    {
        return toAjax(zuaGradeStudentService.insertZuaGradeStudent(zuaGradeStudent));
    }

    /**
     * 修改成绩
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:edit')")
    @Log(title = "成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZuaGradeStudent zuaGradeStudent)
    {
        return toAjax(zuaGradeStudentService.updateZuaGradeStudent(zuaGradeStudent));
    }

    /**
     * 删除成绩
     */
    @PreAuthorize("@ss.hasPermi('zua:grade:remove')")
    @Log(title = "成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(zuaGradeStudentService.deleteZuaGradeStudentByIds(gradeIds));
    }
}
